package com.ces.hk.qrcodeen;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.logging.Logger;

import javax.imageio.ImageIO;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;

public class QrodeenUtil {

	public static void createQrodeen(String path, String content) {
		try {
			MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
			Hashtable hints = new Hashtable();
			hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
			BitMatrix bitMatrix = multiFormatWriter.encode(content,
					BarcodeFormat.QR_CODE, 400, 400, hints);
			File file1 = new File(path, "888.jpg");
			MatrixToImageWriter.writeToFile(bitMatrix, "jpg", file1);
			overlapImage(path+"\\888.jpg", "C:\\Documents and Settings\\xiushan\\Desktop\\567.png");
		} catch (Exception e) {
			Logger.getLogger("QrodeenUtil").info(e.toString());
		}
	}
	
	private static void overlapImage(String bigPath, String smallPath) {
        try {
          BufferedImage big = ImageIO.read(new File(bigPath));
          BufferedImage small = ImageIO.read(new File(smallPath));
          Graphics2D g = big.createGraphics();
          g.drawImage(small, 180, 180, 40, 40, null);
          g.dispose();
          ImageIO.write(big, "jpg", new File(bigPath));
        } catch (Exception e) {
          e.printStackTrace();
        }
    } 

	public static void main(String[] args) {
		String content = "120605181003;http://www.cnblogs.com/jtmjx";
		String path = "C:\\Documents and Settings\\xiushan\\Desktop\\yunfengqiao of jar";
		createQrodeen(path, content);
	}
}
